/**
* Abstract: GameNova Sound & Music Library
*
* Version: 1.0
*
* Disclaimer: IMPORTANT:  This Gamenova software is supplied to you by
* 4E Studios Srl("4E") in consideration of your agreement to the following terms,
* and your use, installation, modification or redistribution of this 4E software
* constitutes acceptance of these terms.  If you do not agree with these terms,
* please do not use, install, modify or redistribute this 4E software.
*
* In consideration of your agreement to abide by the following terms, and subject
* to these terms, 4E grants you a personal, non-exclusive license, under
* 4E's copyrights in this original 4E software (the "4E Software"), to
* use, reproduce, modify and redistribute the 4E Software, with or without
* modifications, in source and/or binary forms; provided that if you redistribute
* the 4E Software in its entirety and without modifications, you must retain
* this notice and the following text and disclaimers in all such redistributions
* of the 4E Software.
* Neither the name, trademarks, service marks or logos of 4E Studios Srl may be used
* to endorse or promote products derived from the 4E Software without specific
* prior written permission from 4E.  Except as expressly stated in this notice,
* no other rights or licenses, express or implied, are granted by 4E herein,
* including but not limited to any patent rights that may be infringed by your
* derivative works or by other works in which the 4E Software may be
* incorporated.
*
* The 4E Software is provided by 4E on an "AS IS" basis.  4E MAKES NO
* WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, REGARDING THE 4E SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
* COMBINATION WITH YOUR PRODUCTS.
*
* IN NO EVENT SHALL 4E BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR
* DISTRIBUTION OF THE 4E SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF
* CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF
* 4E HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright (C) 2011 4E Studios Srl All Rights Reserved.
*/


/**

    GameNova Audio Library
    @overview
*/


/**
    Gamenova Audio Library Main Class
    @constructor
    
*/
function GNAudio(){

    /**
        @description List of the sounds loaded.
        @property
    */
    this.sounds = {};

     /**
        Load a Sound file.
        @function
        @param {string} name    Application name for the sound file.
        @param {string} url     Url of the sound file to load.
        @param {object} callback    User defined allback function called when the sound has been loaded.
    */
    this.loadSound = function(name, url, callback) {

       
        var audioElement = document.createElement('audio');
        audioElement.setAttribute('preload', 'auto');
        this.sounds[name] = audioElement;
        this.sounds[name].loaded = false;
        this.sounds[name].onLoadClb = (callback || function() {});

        var sounds = this.sounds;

        audioElement.addEventListener('canplay', function(evt) {

              sounds[name].loaded = true;

              sounds[name].onLoadClb(evt);

        });

         
        audioElement.setAttribute('src', url);

       
        audioElement.stop = function() {
            this.currentTime = 0;
            this.pause();
        };

        audioElement.load();
    };

};

window.GNAudio =  new GNAudio();

